<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * Char_field:
 * 'max_length' goes into 'data_length' field, but makes more sense to the end user.
 */
class Char_field extends Db_field
{
	// Set the defaults
	protected $defaults = array(
		'data_type' => 'VARCHAR',
		'data_length' => 255
	);
	
	public function __construct(Array $properties)
	{
		// Extend defaults with passed-in properties
		$properties = array_merge($this->defaults, $properties);
		
		// This is a MySQl imposed limit on varchar.
		// This should probably be a database dependent limit.
		if(isset($properties['max_length']))
		{
			if($properties['max_length'] > 255)
			{
				$this->defaults['data_length'] = 255;
			}
			else
			{
				$this->defaults['data_length'] = $properties['max_length'];
			}
		}
		
		parent::__construct($properties);
	} // end __construct
	
} // end Char_field